/*
 * @Author: your name
 * @Date: 2021-12-23 12:44:15
 * @LastEditTime: 2021-12-23 12:51:23
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue\vue-douban-rd\routes\db.js
 */
var mysql = require('mysql');//加载mysql程序驱动模块
var connection = mysql.createPool({
  //与mysql数据库建立连接
  connectionLimit : 10,
  host: 'localhost',
  user: 'root',
  password: '',
  database: 'my_movies'
});

function query(sql,params) {
  return new Promise((resolve, reject) => {
    connection.query(sql,params, function (error, results) {
      if (error) {
        reject(error);//抛出错误
      }
      resolve(results);//返回结果
    });
  });
}


module.exports = {
    query,
}